#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk
import gnome.ui
import gtk.glade

import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar

from gcapplet import globals

class auth():
	is_ok = False
	def __init__(self):
		glade_file =  globals.DATA_DIR + '/calendar.glade'
		glade_tree = gtk.glade.XML(glade_file)
		
		self.auth_window =  glade_tree.get_widget('auth_window')
		self.ok_button =  glade_tree.get_widget('ok_button')
		self.cancel_button =  glade_tree.get_widget('cancel_button')
		self.uname_field =  glade_tree.get_widget('uname_field')
		self.pwd_field =  glade_tree.get_widget('pwd_field')
		
		self.ok_button.connect('clicked', self.get_auth, self.uname_field, self.pwd_field)
		self.auth_window.show_all()
	
	def get_auth(self, widget, uname_field, pwd_field):
		username = uname_field.get_text()
		password = pwd_field.get_text()
		
		self.login = gdata.calendar.service.CalendarService()
		self.login.email = username
		self.login.password = password
		self.login.source = 'Google-Calendar_Python_Sample-1.0'
		try:
			self.login.ProgrammaticLogin()
			self.is_ok = True
			print('Success!')
		except:
			self.is_ok = False
			print('False!')
		self.auth_window.hide_all()
		
